--require "MainScene"

ZhuangBeiScene={}
ZhuangBeiSceneFunc={}
ZhuangBeiSceneFunc.__index = ZhuangBeiSceneFunc
setmetatable(ZhuangBeiScene, ZhuangBeiSceneFunc)

ZhuangBeiScene.NodeID  = {Menu=1001, CloseButton=1002, MenuItem1=2001, MenuItem2=2002, MenuItem3=2003, MenuItem4=2004}

--ZhuangBeiScene.contentLayer = nil
--ZhuangBeiScene.menuSelected = -1 
--ZhuangBeiScene.menu = nil 


ZhuangBeiSceneFunc.getNode = function(self)
  local l = {}
  l.node = CCBReader:load("ZhuangBeiScene.ccbi")
  print("ZhuangBeiScene.getNode", ZhuangBeiScene.node)
  setmetatable(l, ZhuangBeiSceneFunc)
  ZhuangBeiScene.instance = l
  l:init() 
  return l 
end

ZhuangBeiSceneFunc.getScene = function(self)
  local sc = CCScene:create()
  sc:addChild(ZhuangBeiScene.getNode().node)  
  print("ZhuangBeiScene.getScene", sc)
  return sc
end

ZhuangBeiSceneFunc.init = function(self)
  setObjectExtTable(self.node:getChildByTag(ZhuangBeiScene.NodeID.CloseButton), self)
  self.radioMenu = RadioMenu:create(self.node:getChildByTag(ZhuangBeiScene.NodeID.Menu), "menuItemChanged", self) 
  self.radioMenu:setMenuState(0)

--[[
  self.menu = self.node:getChildByTag(ZhuangBeiScene.NodeID.Menu)
  self.menuSelected = -1 
  self:setMenuState(3)
  setObjectExtTable(self.menu:getChildByTag(ZhuangBeiScene.NodeID.MenuItem1), self)
  setObjectExtTable(self.menu:getChildByTag(ZhuangBeiScene.NodeID.MenuItem2), self)
  setObjectExtTable(self.menu:getChildByTag(ZhuangBeiScene.NodeID.MenuItem3), self)
  setObjectExtTable(self.menu:getChildByTag(ZhuangBeiScene.NodeID.MenuItem4), self)
]]
end

--[[
ZhuangBeiSceneFunc.getMenuItemIndex = function(self, node)
  local items = self.menu:getChildren()
  for i=0,items:count()-1 do
    local item = items:objectAtIndex(i)
    item = TypeCast(item, "CCMenuItem")
    if item==node then
      return i
    end
  end 
end]]
ZhuangBeiSceneFunc.menuItemChanged = function(self, oldIndex, newIndex)
  if self.contentLayer~=nil then
    self.node:removeChild(self.contentLayer.node, true)
  end
  self:clearLayers()
  if newIndex==0 then
    self.contentLayer = ZBCDLayer:getNode()
  elseif newIndex==1 then
    self.contentLayer = ZBQHLayer:getNode()
  elseif newIndex==2 then
    self.contentLayer = ZBHCLayer:getNode()
  elseif newIndex==3 then
    self.contentLayer = BSHCLayer:getNode()
  end
  self.node:addChild(self.contentLayer.node)
  self.currentSelect = newIndex 
  if newIndex==0 then 
    ZhuangBeiGuide.nextStep()
  end
end
ZhuangBeiSceneFunc.clearLayers = function(self)
  ZBCDLayer.instance = nil
  ZBQHLayer.instance = nil
  ZBHCLayer.instance = nil
  BSHCLayer.instance = nil
end
ZhuangBeiSceneFunc.onCloseZhuangBeiScene = function(self, node, event)
  node:getParent():getParent():removeChild(node:getParent(), true)
  ZhiHuiBuScene.instance = nil
  --ZBQHLayer.instance = nil
  self:clearLayers()
  print("ZhuangBeiSceneFunc.onCloseZhuangBeiScene", self.toNode, self.callback)
  if self.toNode==nil then
    setTouchEnabledAll(MainScene.node, true)
    MainScene.setState()
  else
    if self.callback~=nil then
      self.callback(self.toNode)
    end
    --setTouchEnabledAll(self.toNode.node, true)
  end
end
